﻿using System;
using System.ComponentModel;
using System.Data.Linq;
using System.Data.Linq.Mapping;

namespace STS.Model
{
    [Table]
    public class Poi : INotifyPropertyChanged, INotifyPropertyChanging
    {
        private int _poiId;

        [Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
        public int PoiId
        {
            get { return _poiId; }
            set
            {
                if (_poiId != value)
                {
                    NotifyPropertyChanging("PoiId");
                    _poiId = value;
                    NotifyPropertyChanged("PoiId");
                }
            }
        }

        // Define name: private field, public property, and database column.
        private string _name;

        [Column]
        public string Name
        {
            get { return _name; }
            set
            {
                if (_name != value)
                {
                    NotifyPropertyChanging("Name");
                    _name = value;
                    NotifyPropertyChanged("Name");
                }
            }
        }

        private string _content;

        [Column]
        public string Content
        {
            get { return _content; }
            set
            {
                if (_content != value)
                {
                    NotifyPropertyChanging("Content");
                    _content = value;
                    NotifyPropertyChanged("Content");
                }
            }
        }

        private string _image;

        [Column]
        public string Image
        {
            get { return _image; }
            set
            {
                if (_image != value)
                {
                    NotifyPropertyChanging("Image");
                    _image = value;
                    NotifyPropertyChanged("Image");
                }
            }
        }

        private double? _lat;

        [Column(CanBeNull = true)]
        public double? Lat
        {
            get { return _lat; }
            set
            {
                if (_lat != value)
                {
                    NotifyPropertyChanging("Lat");
                    _lat = value;
                    NotifyPropertyChanged("Lat");
                }
            }
        }

        private double? _lng;

        [Column(CanBeNull = true)]
        public double? Lng
        {
            get { return _lng; }
            set
            {
                if (_lng != value)
                {
                    NotifyPropertyChanging("Lng");
                    _lng = value;
                    NotifyPropertyChanged("Lng");
                }
            }
        }


#pragma warning disable
        // Version column aids update performance.
        [Column(IsVersion = true)]
        private Binary _version;
#pragma warning restore

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        // Used to notify that a property changed
        private void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion

        #region INotifyPropertyChanging Members

        public event PropertyChangingEventHandler PropertyChanging;

        // Used to notify that a property is about to change
        private void NotifyPropertyChanging(string propertyName)
        {
            if (PropertyChanging != null)
            {
                PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
            }
        }

        #endregion
    }
}
